export default {
  get(key) {
    const name = key + '='
    const ca = document.cookie.split(';')
    for (let i = 0; i < ca.length; i++) {
      const c = ca[i].trim()
      if (c.indexOf(name) === 0) {
        return c.substring(name.length, c.length)
      }
    }
    return ''
  },

  set(key, value) {
    const d = new Date()
    d.setTime(d.getTime() + 30 * 24 * 60 * 60 * 1000)
    const expires = 'expires=' + d.toGMTString()
    document.cookie = key + '=' + value + '; ' + expires
  },

  remove(name) {
    const exp = new Date()
    exp.setTime(exp.getTime() - 1)
    const cVal = this.get(name)
    if (cVal != null) document.cookie = name + '=' + cVal + ';expires=' + exp.toGMTString()
  }
}
